package edu.jd.movieplatform.security.m_login;


import edu.jd.movieplatform.common.MTokenUtils;
import edu.jd.movieplatform.common.Result;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/security/m_login")
public class MLoginAPI {
    @Resource
    private MLoginService mloginService;

    @PostMapping("")//表示直接用父地址,只接收post类型
    public Result m_login(@RequestBody MLoginDto dto){

        boolean ok = mloginService.checkMLogin(dto);

        if (ok){
            //生成一个登录令牌
            String token = MTokenUtils.MloginSign(dto.getMan_id(),dto.getPassword());
            return Result.success((Object)token);//向客户端发送成功型号，并发送令牌
        }

        return Result.fail(Result.ERR_CODE_PWD,"账号或密码错误");

    }

}
